﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataLib.Common;
using DataLib.Model;
using System.Data;

namespace DataLib.BLL
{
    public class CJOItem
    {
        private readonly DataLib.DAL.CJOItem dal = new DataLib.DAL.CJOItem();
        public Model.CJOItem GetListByCid(int cid)
        {
            return dal.GetListByCid(cid);
        }

        public List<DataLib.Model.CJOItem> GetCJOList(string where)
        {
            return dal.GetCJOList(where);
        }

                /// <summary>
        /// 可以联合查询的数据集，关联LoadNum l，VehicleRequire v，Cumtomer cum，CumtomerAddress cumadd，Cjo c
        /// </summary>
        /// <param name="where">条件字段需带上表名</param>
        /// <returns></returns>
        public DataTable GetCJOitemTable(string where)
        {
            return dal.GetCJOitemTable(where);
        }

               /// <summary>
        /// 新增一张CJO，
        /// </summary>
        /// <param name="lModel">如果是从原有Load新开CJO，则LoadID为零</param>
        /// <param name="cModel">CJO</param>
        /// <param name="vModel"></param>
        /// <returns></returns>
        public int InsertCjoItem(Model.LoadNum lModel, Model.Cjo cModel, Model.VehicleRequire vModel)
        {
            return dal.InsertCjoItem(lModel,cModel, vModel);
        }

               /// <summary>
        /// 修改一张CJO，
        /// </summary>
        /// <param name="lModel">LoadNum</param>
        /// <param name="cModel">CJO</param>
        /// <param name="vModel"></param>
        /// <returns></returns>
        public int UpdateCjoItem(Model.LoadNum lModel, Model.Cjo cModel, Model.VehicleRequire vModel)
        {
            return dal.UpdateCjoItem(lModel, cModel, vModel);
        }

        /// <summary>
        /// 获取当前load下最新cjoid
        /// </summary>
        /// <param name="loadid"></param>
        /// <returns></returns>
        public int GetCjoId(int loadid)
        {
            int cjoid = 0;
            DataTable dt = new DAL.Cjo().GetList("loadnumid=" + loadid.ToString()).Tables[0];
            if (dt != null && dt.Rows.Count > 0)
            {
                cjoid = int.Parse(dt.Rows[dt.Rows.Count-1]["id"].ToString());
            }
            return cjoid;
        }

        /// <summary>
        /// 无条件查询
        /// </summary>
        /// <returns></returns>
        public DataTable GetCJOitemDt()
        {
            DataTable dt = GetCJOitemDt("", "", "", "", "", "", "", "", "", "","");
            return dt;
        }

        /// <summary>
        /// 根据本地异地状态，处理地，CJO状态获取详细列表
        /// </summary>
        /// <param name="islocal">是否本地</param>
        /// <param name="graphic">处理地</param>
        /// <param name="cstatus">CJO状态</param>
        /// <returns></returns>
        public DataTable GetCJOitemDt(string islocal,string graphic,string cstatus)
        {
            DataTable dt = GetCJOitemDt("","","","",graphic,"","",cstatus,"","",islocal);
            return dt;
        }

        public DataTable GetCJOitemDt(string cjostatus,string loadstatus,string saleman,string graphic)
        {
            DataTable dt = GetCJOitemDt("", "", "", "", graphic, saleman, loadstatus, cjostatus, "", "", "");
            return dt;
        }

        public DataTable GetCJOitemDt(string cjostatus, string belong)
        {
            DataTable dt = GetCJOitemDt("", "", "", belong, "", "", "", cjostatus, "", "", "");
            return dt;
        }

        public DataTable GetCJOitemDt(string cjostatus, string loadstatus, string saleman, string graphic, string islocal)
        {
            return GetCJOitemDt("", "", "", "", graphic, saleman, loadstatus, cjostatus, "", "", islocal);
        }


        /// <summary>
        /// 返回ＣＪＯ的详细列表
        /// </summary>
        /// <returns></returns>
        public DataTable GetCJOitemDt(string LoadNum, string cjono, string Cum, string belongcity, string graphicity, string saleman, string loadstatus, string cjostatus, string StartDate, string EndDate,string isLocal)
        {
            if (EndDate != "")
            {
                DateTime t = DateTime.Parse(EndDate).AddDays(1).AddSeconds(-1);
                EndDate = t.ToString();
            }
            return dal.GetCJOitemDt(LoadNum, cjono, Cum, belongcity, graphicity, saleman, loadstatus, cjostatus, StartDate, EndDate,isLocal);
        }

           /// <summary>
        /// 返回LoadStatus进程列表
        /// </summary>
        /// <param name="city">处理地</param>
        /// <returns></returns>
        public DataTable GetLoadStatusList(string city)
        {
            return dal.GetLoadStatusList(city);
        }

        /// <summary>
        /// 返回CJO列表，含项目信息
        /// </summary>
        /// <param name="city">处理地</param>
        /// <returns></returns>
        public DataTable GetList_PROCJO(string bcity, string gcity, int islocal, int cstatus)
        {
            return dal.GetList_PROCJO(bcity, gcity, islocal, cstatus);
        }

               /// <summary>
        /// 获取退动直销列表
        /// </summary>
        /// <param name="city">处理地</param>
        /// <returns></returns>
        public DataTable GetDirectSellList(string city)
        {
            return dal.GetDirectSellList(city);
        }


        /// <summary>
        /// 返回LoadStatus进程列表
        /// </summary>
        /// <param name="city">处理地</param>
        /// <returns></returns>
        public DataTable GetLoadStatusList(string uerName, int currpage, int length, out int totalRecord, string search, string city, string order_column, string order_dir, string uname)
        {
            return dal.GetLoadStatusList(uerName, currpage, length, out totalRecord, search, city, order_column, order_dir, uname);
        }

        
        /// <summary>
        /// 取得待授权列表
        /// </summary>
        /// <param name="uerName"></param>
        /// <returns></returns>
        public DataTable getAuthList(int currpage, int length, out int totalRecord, string search, string city, string order_column, string order_dir, string username)
        {
            return dal.getAuthList(currpage, length, out totalRecord, search, city, order_column, order_dir, username);
        }


        /// <summary>
        /// 2016年12月27日 21:30:49
        /// Redplum
        /// 待称重分页 异步调用
        /// </summary>
        /// <param name="bcity"></param>
        /// <param name="gcity"></param>
        /// <param name="currpage"></param>
        /// <param name="length"></param>
        /// <param name="totalRecord"></param>
        /// <param name="search"></param>
        /// <returns></returns>
        public DataTable GetWatiInsByStore(int currpage, int length, out int totalRecord, string search, string bcity, string gcity, string order_column, string order_dir,string user)
        {
            return dal.GetWatiInsByStore(currpage, length, out  totalRecord, search, bcity, gcity, order_column, order_dir,user);
        }
    }
}
